#-------------------------------------------------------------------
# Project Invasion of the aliens 
# name game.py
# purpose level stuff
#
# authors Chris L'Heureux, Tyler Plante, Jackson Morse, Matt Hahn
# main author: Matt Hahn
#
# created 12/3/12
# Copyright (C) Chris L'Heureux
# License New BSD\
#------------------------------------------------------------------  
import pygame, math, sys
from Blocks.CaveBlock import CaveBlock
from Blocks.CloudBlock import CloudBlock
from Blocks.CoralBlock import CoralBlock
from Blocks.DirtBlock import DirtBlock
from Blocks.FishBlock import FishBlock
from Blocks.FogBlock import FogBlock
from Blocks.GlassBlock import GlassBlock
from Blocks.LavaBlock import LavaBlock
from Blocks.LeafBlock import LeafBlock
from Blocks.LightningBlock import LightningBlock
from Blocks.MountainBlock import MountainBlock
from Blocks.QuicksandBlock import QuicksandBlock
from Blocks.SeaWeedBlock import SeaWeedBlock
from Blocks.SkyBlock import SkyBlock
from Blocks.StalagmiteBlock import StalagmiteBlock
from Blocks.StoneBlock import StoneBlock
from Blocks.TreeBlock import TreeBlock
from Blocks.UnderWorldBlock import UnderWorldBlock
from Blocks.VineBlock import VineBlock
from Blocks.WaterBlock import WaterBlock
from Blocks.WoodBlock import WoodBlock

class level():
    def __init__(self, level, screenSize):
        self.screenSize = screenSize
        self.screenWidth = screenSize[0]
        self.screenHeight = screenSize[1]
        self.blockSize = 25
        self.load(level)
        
    def load(self, level):
        self.block1 = []
        self.block2 =[]
        self.block3 = []
        self.block4 = [] 
        self.block5 = []
        self.block6 = []
        self.block7 = []
        self.block8 = []
        self.block9 = []
        self.block10 = []
        self.block11 = []
        self.block12 = []
        self.block13 = []
        self.block14 = []
        self.block15 = []
        self.block16 = []
        self.block17 = []
        self.block18 = []
        self.block19 = []
        self.block20 = []
        self.block21 = []
        
        geoMap="Maps/"+ level
        geofile = open(geoMap, "r")
        lines = geofile.readlines()
        geofile.close()
        newlines = []
        self.nspawn = False
        
        for line in lines:
            newline = ""
            for character in line:
                if character != "\n":
                    newline += character
            newlines += [newline]
            
        for y, line in enumerate(newlines):
            for x, c in enumerate(line):
                if c == "m":
                    self.block1 += [TreeBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]
            for x, c in enumerate(line):
                if c == "q":
                    self.block2 += [CaveBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]
            for x, c in enumerate(line):
                if c == "w":
                    self.block3 += [CloudBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]
            for x, c in enumerate(line):
                if c == "e":
                    self.block4 += [CoralBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]
            for x, c in enumerate(line):
                if c == "r":
                    self.block5 += [DirtBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]
            for x, c in enumerate(line):
                if c == "t":
                    self.block6 += [FishBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]
            for x, c in enumerate(line):
                if c == "y":
                    self.block7 += [FogBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]
            for x, c in enumerate(line):
                if c == "u":
                    self.block8 += [GlassBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]
            for x, c in enumerate(line):
                if c == "i":
                    self.block9 += [LavaBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]
            for x, c in enumerate(line):
                if c == "o":
                    self.block10 += [LeafBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]
            for x, c in enumerate(line):
                if c == "p":
                    self.block11 += [LightningBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]
            for x, c in enumerate(line):
                if c == "a":
                    self.block12 += [MountainBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]
            for x, c in enumerate(line):
                if c == "s":
                    self.block13 += [QuicksandBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]
            for x, c in enumerate(line):
                if c == "d":
                    self.block14 += [SeaWeedBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]
            for x, c in enumerate(line):
                if c == "f":
                    self.block15 += [SkyBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]
            for x, c in enumerate(line):
                if c == "g":
                    self.block16 += [StalagmiteBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]
            for x, c in enumerate(line):
                if c == "h":
                    self.block17 += [StoneBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]
            for x, c in enumerate(line):
                if c == "j":
                    self.block18 += [UnderWorldBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]
            for x, c in enumerate(line):
                if c == "k":
                    self.block19 += [VineBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]
            for x, c in enumerate(line):
                if c == "l":
                    self.block20 += [WaterBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]
            for x, c in enumerate(line):
                if c == "z":
                    self.block21 += [WoodBlock(self.blockSize, 
                                                [(x*self.blockSize)+self.blockSize/2, 
                                                 (y*self.blockSize)+self.blockSize/2],
                                                 self.screenSize)
                                                ]